﻿function OpenDialog2(strURL, str_width, str_height, str_value, str_element, str_postback) {
    try {
        var var_time = new Date();
        var winoption = "dialogWidth=" + str_width + "px;dialogHeight=" + str_height + "px;status:no; directories:yes;scrollbars:auto;Resizable=yes;";

        var tmp = window.showModalDialog(strURL + "&vt=" + var_time, '', winoption);
        if (tmp != null && tmp != "" && tmp != undefined) {
            document.getElementById(str_element).value = tmp;
            if (str_postback == "1") {
                document.getElementById(str_element).onchange();
            }
        }
    } catch (e) {
    }
}

function Open2(strURL, str_width, str_height) {
    try {
        var var_time = new Date();
        var winoption = "dialogWidth=" + str_width + "px;dialogHeight=" + str_height + "px;status:no; directories:yes;scrollbars:auto;Resizable=yes;";
        var tmp = window.open(strURL + "&vt=" + var_time, '', winoption);

    } catch (e) {
    }
}

function Open3(strURL, str_width, str_height) {
    try {
        var winoption = "dialogWidth=" + str_width + "px;dialogHeight=" + str_height + "px;status:no; directories:yes;scrollbars:auto;Resizable=yes;";
        var tmp = window.open(strURL, '', winoption);

    } catch (e) {
    }
}

function FileHandler(File)
{
    var Width = 30;
    var Height = 30;
    var Top = (window.screen.availHeight-100-Height)/2;
    var Left = (window.screen.availWidth-220-Width)/2;
    window.open(File,'DownLoadFile','height='+Height+',,innerHeight='+Height+',width='+Width+',innerWidth='+Width+',top='+Top+',left='+Left+',toolbar=no,menubar=no,scrollbars=auto,resizeable=yes,location=no,status=no');
}

function JSInfomation(info, IsCloseForm)
{
    alert(info);
    if (IsCloseForm) {
        window.close();
    }
}

function SaveAsDraft_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认要保存草稿?')) {
        return false;
    }
    return true;
}

function Save_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认要保存?')) {
        return false;
    }
    return true;
}

function Forward_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认要提交转发?')) {
        return false;
    }
    return true;
}

function Submit_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认要提交?')) {
        return false;
    }
	button.style.display='none';
	return true;
}

function SMS_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认要发送短信?')) {
        return false;
    }
    button.style.display = 'none';
    return true;
}

function Email_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认要发送邮件?')) {
        return false;
    }
    button.style.display = 'none';
    return true;
}

function Approve_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认审批通过 ?')) {
        return false;
    }
    button.style.display = 'none';
    return true;
}

function Close_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认状态关闭 ?')) {
        return false;
    }
    button.style.display = 'none';
    return true;
}

function Delete_PreCallBack(button) {
    if (!confirm('您确认要删除?')) {
        return false;
    }
    return true;
}

function ToPay_PreCallBack(button) {
    if (!confirm('您确认要进行款项支付?')) {
        return false;
    }
    return true;
}

function Abort_PreCallBack(button) {
    DeleteDiv();
    if (!confirm('您确认要中止流程?流程将会被删除!')) {
        return false;
    }
    button.style.display = 'none';
    return true;
}

function ScrollMessageDiv(p)
{
     var d = document,w = window,o = d.getElementById(p.id),ie6 = /msie 6/i.test(navigator.userAgent);
     if (o) {
         o.style.cssText += ";position:" + (p.f && !ie6 ? 'fixed' : 'absolute') + ";" + (p.r ? 'left' : "right") + ":0;" + (p.t != undefined ? 'top:' + p.t + 'px' : 'bottom:0');
         if (!p.f || ie6) {
            -function () {
                var t = 500, st = d.documentElement.scrollTop || d.body.scrollTop, c;
                c = st - o.offsetTop + (p.t != undefined ? p.t : (w.innerHeight || d.documentElement.clientHeight) - o.offsetHeight);
                c != 0 && (o.style.top = o.offsetTop + Math.ceil(Math.abs(c) / 10) * (c < 0 ? -1 : 1) + 'px', t = 10);
                setTimeout(arguments.callee, t)
            } ()
         }
     }
}

function ShowMessage(htmlvalue, count) {
    if(document.getElementById("divMes"))DeleteDiv();
    var PRINT_A = document.getElementById("divFrame");
     var div_box = document.createElement('DIV');
     div_box.id = 'divMes';
     div_box.style.position = 'absolute';
     var w = PRINT_A.offsetWidth;
     var h = PRINT_A.offsetHeight - (count * 28);
     div_box.style.left = (PRINT_A.offsetWidth + 12) + "px";
     div_box.style.top = "0px";
     div_box.style.width = '240px';
     div_box.style.background = '#FFFFFF';
     div_box.style.visibility = 'visible';
     div_box.innerHTML = "<div style='border:solid 1px Orange;padding:6px 10px 10px 0px; margin:6px 0px 10px 0px; font-size:12px; color:#000000;'>"+htmlvalue+"</div>";
     document.body.appendChild(div_box);
     ScrollMessageDiv({id:'divMes',t:0});
}

function DeleteDiv() 
{
    try {
        var div = document.getElementById('divMes');
        div.parentNode.removeChild(div);

    } catch (e) {
    }
}

function winOpenForm(strURL, id) {
    document.getElementById(id).style.display = "none";
    var sheight = screen.height - 150;
    var swidth = screen.width - 10;
    var winoption = "left=0,top=0,height=" + sheight + ",width=" + swidth + ",toolbar=yes,menubar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes";
    var tmp = window.open(strURL, '', winoption);
    return tmp;
}

function winOpenFormNoHide(strURL) {
    var sheight = screen.height - 150;
    var swidth = screen.width - 10;
    var winoption = "left=0,top=0,height=" + sheight + ",width=" + swidth + ",toolbar=yes,menubar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes";
    var tmp = window.open(strURL, '', winoption);
    return tmp;
}

function PrintView(ID)
{
    //var sprnhtml = document.getElementById(ID).outerHTML;
    //var selfhtml = window.document.body.innerHTML;//获取当前页的html
    //window.document.body.innerHTML = sprnhtml;
    window.print();
    //window.document.body.innerHTML=selfhtml;

    //局部打印后，当前页面打印区域外的操作都不好用了，所采用了当执行打印时重新刷新页面
    //window.location.reload(); 
}

function PageSetup_Null() 
{
//    //设置网页打印的页眉页脚为空
//    var Wsh = new ActiveXObject("WScript.Shell");
//    var HKEY_Root, HKEY_Path, HKEY_Key;
//    HKEY_Root = "HKEY_CURRENT_USER";
//    HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//    HKEY_Main = "\\Software\\Microsoft\\Internet Explorer\\Main\\";
//    HKEY_Key = "header";
//    Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
//    HKEY_Key = "footer";
//    Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "新城控股:&p/&P");
//    HKEY_Key = "margin_left"
//    Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.2"); //键值设定--左边边界 
//    HKEY_Key = "margin_top"
//    Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.59055"); //键值设定--上边边界 
//    HKEY_Key = "margin_right"
//    Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.2"); //键值设定--右边边界 
//    HKEY_Key = "margin_bottom"
//    Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.86614"); //键值设定--下边边界
//    try {
//        HKEY_Key = "Print_Background"
//        Wsh.RegWrite(HKEY_Root + HKEY_Main + HKEY_Key, "yes");     //打印背景图
//    } catch (exception)
//    { }
}

function doPrint() 
{
    try {
        PageSetup_Null();
    }
    catch (e) {
        var errorMsg = e.message + "\r" + "请设置:IE选项->安全->Internet->" + "ActiveX控件和插件" + "\r" + "对未标记为可安全执行脚本的ActiveX的控件初始化并执行脚本->允许/提示";
        alert(errorMsg);
        return;
    }
    window.print();
} 

//页签切换
function changeTab(obj, divTab, url) {
    document.getElementById("divForm").style.display = "none";
    document.getElementById("divMonitor").style.display = "none";
    document.getElementById(divTab).style.display = "block";

    if (divTab == "divForm") {
        document.getElementById("divFrame").className = "divForm";
    }
    if (divTab == "divMonitor") {
        document.getElementById("divFrame").className = "divMonitor";
        if (document.getElementById("frmMonitor").src == "") {
            document.getElementById("frmMonitor").src = url;
        }
    }
}

String.prototype.startWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substr(0, str.length) == str)
        return true;
    else
        return false;
    return true;
}

String.prototype.endWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substring(this.length - str.length) == str)
        return true;
    else
        return false;
    return true;
}


//监控页面自适应高度
function checkMonitorIFrameHeight() {
    var s = document.getElementById("frmMonitor").contentWindow.document.documentElement.scrollHeight;
    var H = s <= 500 ? 500 : s;
    document.getElementById("frmMonitor").style.height = H + "px";
    document.getElementById("divMonitor").style.height = H + "px";
}

//spFrame.js-start
function publishHeight() {
    if (window.location.hash.length == 0) return;
    var frameId = getFrameId();
    if (frameId == '') return;
    var actualHeight = getBodyHeight();
    var currentHeight = getViewPortHeight();

    if (Math.abs(actualHeight - currentHeight) > 15) {
        var hostUrl = window.location.hash.substring(1);
        hostUrl += "#";
        hostUrl += 'frameId=' + frameId;
        hostUrl += '&';
        //hostUrl += 'height=' + (actualHeight < 442 ? 442 : actualHeight).toString();
        hostUrl += 'height=' + actualHeight.toString();

        window.top.location = hostUrl;
    }
}

function getFrameId() {
    try
    {
        var qs = parseQueryString(window.location.href);
        var frameId = qs["frameId"];
        var hashIndex = frameId.indexOf('#');
        if (hashIndex > -1) {
            frameId = frameId.substring(0, hashIndex);
        }
    }catch(exception) {
    }
    return frameId;
}

function getBodyHeight() {

    var height,
        scrollHeight,
        offsetHeight;

    if (document.height) {
        height = document.height;
    } else if (document.body) {
        if (document.body.scrollHeight) {
            height = scrollHeight = document.body.scrollHeight;
        }
        if (document.body.offsetHeight) {
            height = offsetHeight = document.body.offsetHeight;
        }
        if (scrollHeight && offsetHeight) {
            height = Math.max(scrollHeight, offsetHeight);
        }
    }
    return height;
}

function getViewPortHeight() {
    var height = 0;
    if (window.innerHeight) {
        height = window.innerHeight - 18;
    } else if ((document.documentElement) && (document.documentElement.clientHeight)) {
        height = document.documentElement.clientHeight;
    } else if ((document.body) && (document.body.clientHeight)) {
        height = document.body.clientHeight;
    }

    return height;
}

function parseQueryString(url) {
    url = new String(url);
    var queryStringValues = new Object(),
        querystring = url.substring((url.indexOf('?') + 1), url.length),
        querystringSplit = querystring.split('&');

    for (i = 0; i < querystringSplit.length; i++) {
        var pair = querystringSplit[i].split('='),
            name = pair[0],
            value = pair[1];

        queryStringValues[name] = value;
    }

    return queryStringValues;
}
//spFrame.js-end


//divMessageBox.js - start
function divMsgBox(title, msg, w, h, isErr, root) {
    var showTime = 6000*10*10;
    var t = showTime / 1000;
    var titleheight = "22px";     // 提示窗口标题高度 
    var bordercolor = "#B8C5E7";  // 提示窗口的边框颜色 
    var titlecolor = "#514F48";   // 提示窗口的标题颜色 
    var titlebgcolor = "#B8C5E7"; // 提示窗口的标题背景色
    var bgcolor = "#FFFFFF";      // 提示内容的背景色 		

    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;

    var bgObj = document.createElement("div");
    bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:" + iWidth + "px;height:" + Math.max(document.body.clientHeight, iHeight) + "px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#ccc;z-index:2000;";
    document.body.appendChild(bgObj);

    var msgObj = document.createElement("div");
    msgObj.style.cssText = "position:absolute;font:11px '宋体';top:" + (iHeight - h)/2 + "px;left:" + (iWidth - w) / 2 + "px;width:" + w + "px;height:" + h + "px;text-align:left;border:1px solid " + bordercolor + ";background-color:" + bgcolor + ";padding:0px;line-height:22px;z-index:2000;";
    document.body.appendChild(msgObj);

    var table = document.createElement("table");
    msgObj.appendChild(table);
    table.style.cssText = "margin:0px;border:0px;padding:0px;z-index:2000;";
    table.cellSpacing = 0;
    var tr = table.insertRow(-1);
    var titleBar = tr.insertCell(-1);
    titleBar.style.cssText = "width:100%;height:" + titleheight + "px;text-align:left;padding:0px;margin:0px;font:bold 13px '宋体';color:" + titlecolor + ";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
    titleBar.style.paddingLeft = "10px";
    titleBar.innerHTML = "<div style='float:left;margin-left:-4px;'>" + (isErr ? "<img border='0' src='" + root + "/Resource/Images/Icon_Error.gif'/>" : "<img border='0' src='" + root + "/Resource/Images/Icon_Info.gif'/>") + "</div><div style='padding-top:4px;padding-left:4px;height:100%;float:left;'>" + title + "</div>";
    var moveX = 0;
    var moveY = 0;
    var moveTop = 0;
    var moveLeft = 0;
    var moveable = false;
    var docMouseMoveEvent = document.onmousemove;
    var docMouseUpEvent = document.onmouseup;

    titleBar.onmousedown = function () {
        var evt = getEvent();
        moveable = true;
        moveX = evt.clientX;
        moveY = evt.clientY;
        moveTop = parseInt(msgObj.style.top);
        moveLeft = parseInt(msgObj.style.left);

        document.onmousemove = function () {
            if (moveable) {
                var evt = getEvent();
                var x = moveLeft + evt.clientX - moveX;
                var y = moveTop + evt.clientY - moveY;
                if (x > 0 && (x + w < iWidth) && y > 0 && (y + h < iHeight)) {
                    msgObj.style.left = x + "px";
                    msgObj.style.top = y + "px";
                }
            }
        };

        document.onmouseup = function () {
            if (moveable) {
                document.onmousemove = docMouseMoveEvent;
                document.onmouseup = docMouseUpEvent;
                moveable = false;

                moveX = 0;
                moveY = 0;
                moveTop = 0;
                moveLeft = 0;
            }
        };
    }

    var closeBtn = tr.insertCell(-1);
    closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
    closeBtn.innerHTML = "<span style='font-size:14pt; color:" + titlecolor + ";'>×</span>";
    closeBtn.onclick = divMessagesClose;
    var msgBox = table.insertRow(-1).insertCell(-1);
    msgBox.style.cssText = "font:12pt '宋体';height:50px;";
    msgBox.colSpan = 5;
    msgBox.innerHTML = msg;

    //显示剩余的时间数
    var time = table.insertRow(-1).insertCell(-1);
    //time.style.cssText = "font:9pt '宋体';";
    //time.innerHTML = t+" 秒后自动关闭!"; 


    // 获得事件Event对象，用于兼容IE和FireFox
    function getEvent() {
        return window.event || arguments.callee.caller.arguments[0];
    }

    //处理自动关闭事件
    function autoClose() {
        --t;
        if (t > 0) {
            //time.innerHTML = t + " 秒后自动关闭!";
            setTimeout(autoClose, 1000);
        }
        else {
            setTimeout(divMessagesClose, 1000);
        }
    }

    //关闭
    function divMessagesClose() {
        try
        {
            document.body.removeChild(bgObj);
            document.body.removeChild(msgObj);
        }catch(exception)
        {}
    }

    //处理入口
    setTimeout(autoClose, 1000);
}
//divMessageBox.js - end

//Cookie.js - start
function SetCookie(name, value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 1;               //此 cookie 将被保存 1 天
    var exp = new Date();       //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";addr=6;path=/";
}
function GetCookie(name)        //取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return '';
}
function DelCookie(name)        //删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";addr=6;path=/";
}
//Cookie.js - end

